package io.renren.modules.managerAppUser.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import io.renren.common.utils.*;
import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.collections.MapUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.managerAppUser.entity.AppUserEntity;
import io.renren.modules.managerAppUser.service.AppUserService;

import javax.servlet.http.HttpServletResponse;


/**
 * @author zhubsh
 * @email sd_zhusbh@163.com
 * @date 2018-11-21 11:51:11
 */
@RestController
@RequestMapping("managerAppUser/appuser")
public class AppUserController {
    @Autowired
    private AppUserService appUserService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("managerAppUser:appuser:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<AppUserEntity> appUserList = appUserService.queryList(query);
        int total = appUserService.queryList(query.noLimit()).size();

        PageUtils pageUtil = new PageUtils(appUserList, total, query.getLimit(), query.getCurrPage());

        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("managerAppUser:appuser:info")
    public R info(@PathVariable("id") String id) {
        AppUserEntity appUser = appUserService.queryObject(id);

        return R.ok().put("appUser", appUser);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("managerAppUser:appuser:save")
    public R save(@RequestBody AppUserEntity appUser) {
        appUserService.save(appUser);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("managerAppUser:appuser:update")
    public R update(@RequestBody AppUserEntity appUser) {
        appUserService.update(appUser);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("managerAppUser:appuser:delete")
    public R delete(@RequestBody String[] ids) {
        appUserService.deleteBatch(ids);

        return R.ok();
    }

    @PostMapping("/auditAppUser")
    public R auditAppUser(@RequestBody AppUserEntity appUserEntity) {
        appUserService.audtiAppUser(appUserEntity);
        return R.ok();
    }

    @GetMapping("/exportAppUser")
    public void exportAppUser(@RequestParam Map<String, Object> params, HttpServletResponse response) {
        //查询列表数据
        Query query = new Query(params);

        List<Map<String,Object>> dataList = appUserService.queryMapList(query);
        String fileName = "菏易行VIP用户信息表" + DateUtils.format(new Date(), "yyyyMMddHHmmss") + ".xls"; //文件名称
        String[] tabHeader = {"用户ID,用户姓名,身份证号,车牌号,联系电话,驾驶证号,档案编号,联系地址,申请时间"}; //表头
        String[] colum_name = {"userid","realName","sfzh","cphm","phone","jszh","dabh","address","createTime"};

        new ExportExcel().exportExcel(fileName, tabHeader, colum_name, dataList, response);
    }
}
